package top.hours48.ddbearapi.model;

import lombok.Data;

import java.util.List;

@Data
public class PageResult<T> {
    private static final Integer kPageSize = 20;

    private Integer pageCount;

    private Integer pageSize;

    private Integer pageIndex;

    private List<T> list;

    public static <T>PageResult buildPageResult(Integer pageIndex, Integer count, List<T> list) {
        PageResult<T> pageResult = new PageResult<>();
        Integer pageCount = (int) Math.ceil(count / kPageSize);
        pageResult.setPageIndex(pageIndex);
        pageResult.setPageSize(kPageSize);
        pageResult.setPageCount(pageCount);
        pageResult.setList(list);
        return pageResult;
    }
}
